<template>
  <div class="scoreContainer">
    <!-- 成绩单顶部 -->
    <div class="score-top">
      <img src="../../assets/logo.png" alt="" />
      <h3>Welcome {{ resultModel.name }}</h3>
      <div>
        <span>{{ resultModel.stu_no }}</span>
      </div>
      <a class="logout-button" href="javascript:;" @click="logoutEvent"
        >logout</a
      >
    </div>
    <!-- 成绩单主体部分 -->
    <div class="score-main">
      <div>
        <span>Here is your unoffical transcript,sorted by academic year.</span>
      </div>
      <div class="imageContent">
        <img :src="this.resultModel.tran_img" alt="" />
      </div>
      <el-button @click="downloadEvent">Download Transcript</el-button>
    </div>
  </div>
</template>

<script>
import download from "ly-downloader";

export default {
  data() {
    return {
      //获取成绩单参数
      setModel: {
        token: ""
      },
      //定义返回值
      resultModel: {}
    };
  },

  methods: {
    // 获取页面数据、
    async getUserInfo() {
      var paramsDic = window.sessionStorage.getItem("token");
      this.setModel.token = paramsDic;
      // console.log(paramsDic);
      const { body: res } = await this.$http1(
        this.$urls.ScoresInfo,
        this.setModel
      );
      // console.log(res);
      if (res.Code !== 10000) return this.$message.error(res.Message);
      this.resultModel = res.Result;
    },

    //点击下载事件
    downloadEvent() {
      if (!this.resultModel.file_path) return;
      var strArr = this.resultModel.file_path.split("/");
      download(1, this.resultModel.file_path, strArr.pop());
    },
    // 点击退出登录
    logoutEvent() {
      //清除保存的token
      window.sessionStorage.clear();
      this.$router.push({ path: "/transcripts/login" });
    }
  },

  created() {
    this.getUserInfo();
  }
};
</script>

<style scoped>
.scoreContainer {
  height: 100%;
  width: 100%;
  overflow-y: scroll;
}

.score-top {
  height: 120px;
  background-color: rgb(209, 226, 241);
  border-bottom-width: 1px;
  border-bottom-color: black;
  border-bottom-style: solid;
  position: relative;
}
.score-top > img {
  position: absolute;
  left: 10px;
  width: 80px;
  top: 10px;
}
.score-top > h3 {
  margin: 0px;
  position: absolute;
  font-size: 22px;
  right: 30px;
  top: 15px;
}
.score-top > div {
  position: absolute;
  right: 30px;
  bottom: 45px;
}
.score-top > div > span {
  font-size: 16px;
  font-weight: bold;
  color: rgb(122, 122, 122);
}
.logout-button {
  position: absolute;
  right: 30px;
  bottom: 10px;
  color: red;
  font-size: 16px;
}
.logout-button:hover {
  cursor: pointer;
  color: blue;
}
.score-main {
  position: relative;
  width: 80%;
  margin: 0 auto;
  /* border: 1px solid yellow; */
  margin-top: 5px;
  margin-bottom: 8px;
}
.score-main > div:first-child {
  width: 100%;
  height: 60px;
  /* border: 1px solid red; */
}
.score-main > div:first-child > span {
  line-height: 60px;
  font-size: 20px;
  font-weight: bold;
  /* border: skyblue solid 1px; */
}
.imageContent {
  width: 100%;
  /* border: springgreen 1px solid; */
}
.imageContent > img {
  margin: 20px 10px;
  width: 790px;
  border: 1px solid #eeeeee;
  box-shadow: 3px 3px 3px gray;
}

.score-main > button {
  margin-top: 20px;
  margin-bottom: 20px;
  padding: 10px 200px;
  background-color: #19adb8;
  border: none;
  border-radius: 0.4em;
  color: white;
  font-size: 17px;
}
.score-main > button:hover {
  cursor: pointer;
  border: none;
  color: blue;
}
</style>
